$(document).ready(function(){	
	$('div#encounterPageContent').show();				
	
	$('#btnPriIcd10').bind('click',function(){
		curIcd10CodeId	=	'clinDiagPrimaryIcd10';	
		curIcd10NameId	=	'clinDiagPrimaryDiagnosis';
		showIcd10List(curIcd10CodeId, curIcd10NameId);
	});  
	$('#btnSecIcd10_1').bind('click',function(){
		curIcd10CodeId	=	'clinDiagSecondaryIcd10_1';	
		curIcd10NameId	=	'clinDiagSecondaryDiagnosis_1';
		showIcd10List(curIcd10CodeId, curIcd10NameId);
	});  
	$('#btnSecIcd10_2').bind('click',function(){
		curIcd10CodeId	=	'clinDiagSecondaryIcd10_2';	
		curIcd10NameId	=	'clinDiagSecondaryDiagnosis_2';
		showIcd10List(curIcd10CodeId, curIcd10NameId);
	}); 
		
	/*
	 ICD10 is optional
	  
	$('#clinDiagPrimaryIcd10').blur(function(){
		isNotEmpty($(this), _("Not yet input ICD 10 diagnosis"),"statusMessageClinDiag");
	});
	*/
	
});

function submitForm(loadPrescription){
	if(!isReadyToSubmitDiagnosis()){
		return;
	}
	if ($('#doctorId').val() == '' || $.trim($('#doctorName').val()) == ''){		
		$('#lblEditMessage').css('color', 'red').text(_("Fail! Please check the required fields"));
		$('#doctorName').css('border-color', 'red');
		return;
	} else {
		$('#doctorName').css('border-color', 'AAA');
	}	
	$.ajax({
		type: 	'POST',
		url:	"../GeneralExamination2/EditGeneralExamination2?set_ajax_view",
		data: 	$('#frmClinDiagEdit').serialize(),
		dataType: 'json',
		beforeSend: function() {
			$('#btnSave0').hide();
			$('#btnSave1').hide();
			$('#module-loading').show();
		},
        complete: function() {
			$('#btnSave0').show();
			$('#btnSave1').show();
			$('#module-loading').hide();
		},
		success: function(data) {
			var result = parseInt(data.saved);			
			if (result == 1) {
				$('#encounterId').val(data.encounterId);
				resetInputBorderColor();
				$('#lblEditMessage').text(_("Save successful")).css('color', 'green').show();
				
				if (loadPrescription == 1) {
					$('#toaThuoc').trigger('click');					
					loadOpenPrescription($('#recordId').val());
				}
			} else {
				var obj	=	$("#" + data.errorField);
				obj.css("border-color", "red").focus();
				$('#lblEditMessage').text(_("Disease ID is not exist in ICD 10 database")).css('color', 'red').show();						
			}
		}
	});		
}

function resetInputBorderColor(){
	$(":input").css("border-color", "#AAA");
}

function isReadyToSubmitDiagnosis(){
	$('#lblEditMessage').css('color', 'green').text('');	
	/*
	 * Optional ICD
	 * 
	if(!isNotEmpty($('#clinDiagPrimaryIcd10'), _("Not yet input ICD 10 diagnosis"), "statusMessageClinDiag")){
		$('#lblEditMessage').css('color', 'red').text(_("Fail! Please check the required fields"));
		return false;
	}
	*/	
	return true;
}